package com.hb.gp.impl;

import java.util.List;
import java.util.Map;

import com.hb.gp.GPInsCommand;
import com.hb.gp.GPType;
import com.hb.gp.IGPCommandMessageService;
import com.hb.gp.util.command.APDU_CreateSessionKey;
import com.hb.gp.util.command.APDU_ExternalAuth;

/**
 * 
 * @author shangzk
 *
 */
@GPType(INS = GPInsCommand.INS_82)
public class GPExternalauthEnticate implements IGPCommandMessageService {

	@Override
	public String makeApduMap(String apdu, Map<String, Object> map)
			throws Exception {
		// TODO Auto-generated method stub
		return makeApduMap(apdu, null, map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public String makeApduMap(String apdu, Map<String, Object> varibleMap,
			Map<String, Object> storeMap) throws Exception {
		// TODO Auto-generated method stub
		String response = (String) storeMap.get(VARIBLE_RESPONSE);
		String random = (String) storeMap.get(VARIBLE_RANDOM);
		List<String> initKeys = (List<String>) storeMap.get(KEY_INIT);
		// System.out.println("初始key为：" + initKeys.toString());
		List<String> sessionKey = APDU_CreateSessionKey.createKeyScp02("",
				initKeys, response);
		String request = APDU_ExternalAuth.authention("02", "01", response,
				random, sessionKey);
		// 写入mac和sessionkey
		storeMap.put(VARIBLE_LASTMAC, request.substring(request.length() - 16));
		storeMap.put(KEY_SESSION, sessionKey);
		return request;
	}

}
